package com.banmao.algorithm.No201To300.No232;

import java.util.Stack;

class MyQueue {

    private Stack<Integer> stack = new Stack<Integer>();

    private Stack<Integer> stack2 = new Stack<Integer>();


    public MyQueue() {

    }

    public void push(int x) {
        stack.push(x);
    }

    public int pop() {
        // 将1号栈的元素逐一推入2号栈，取出栈顶元素，然后再推回去
        while(!stack.isEmpty()) {
            Integer pop = stack.pop();
            stack2.push(pop);
        }
        Integer pop = stack2.pop();
        while(!stack2.isEmpty()) {
            stack.push(stack2.pop());
        }
        return pop;
    }

    public int peek() {
        // 将1号栈的元素逐一推入2号栈，取出栈顶元素，然后再推回去
        while(!stack.isEmpty()) {
            Integer pop = stack.pop();
            stack2.push(pop);
        }
        Integer pop = stack2.peek();
        while(!stack2.isEmpty()) {
            stack.push(stack2.pop());
        }
        return pop;
    }

    public boolean empty() {
        return stack.isEmpty();
    }
}
